<template>
  <div>
    <h1>更新单词</h1>
    <el-form>
      <el-form-item label="单词">
        <el-input v-model="selectedWord.word" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="假名">
        <el-input v-model="selectedWord.kana" placeholder=""></el-input>
      </el-form-item>
      <el-form-item label="中文">
        <el-input v-model="selectedWord.chinese" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="handleUpdate">更新</el-button>
    <el-button @click="toList">返回</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selectedWord: {
        checkCount: 0,
        chinese: "",
        id: '',
        kana: "",
        rightCount: 0,
        userId: "0",
        word: ""
      },
      currentPage: 1,
    }
  },
  methods: {
    async handleUpdate() {
      let result = await this.$API.word.updateWord(this.selectedWord);
      if (result.code == 200) {
        this.$message({
          message: "更新成功！",
          type: "success",
        });
        this.$router.push({
          path: "/wordList/list",
          query: {
          currentPage: this.currentPage,
        },
        });
      } else {
        this.$message({
          message: result.msg,
          type: "error",
        });
      }
    },

    toList() {
      this.$router.push({
        path: "/wordList/list",
        query: {
          currentPage: this.currentPage,
        },
      });
    }
  },
  mounted() {
    this.selectedWord = this.$route.query.selectedWord;
    this.currentPage = this.$route.query.currentPage;
  },
}
</script>

<style>

</style>